<template>
    <div>
        <inner-breadcrumb
            @input="breadcrumbChange"
            v-model="key"
            :path="{
                label: this.$t('minor.culture.cultureTitle'),
                key: 'cultureList',
                children:[
                    {
                    key: 'addCultureTemplate',
                    label:this.$t('minor.culture.basicInfo')
                    },{
                    key: 'addCourseType',
                    label:this.$t('minor.culture.courseType')
                    },{
                    key: 'addCourseSet',
                    label:this.$t('minor.culture.courseSet')
                    },{
                    key: 'addChapterSet',
                    label:this.$t('minor.culture.chapterSet'),
                    children:[{
                        key: 'relationTable',
                        label:this.$t('minor.culture.relationTable')
                    },{
                        key: 'catChapter',
                        label: '微专业培养方案模板预览'
                    }]
                }]
        }"
        />
        <div class="edu-page-warp" v-if="key=='cultureList'">
            <condition-card @reset="resetQuery" @search="searchData">
                <!--事件-->
                <el-row>
                    <!-- <el-col :span="8">
                        <el-form-item :label="$t('minor.major.college')">
                            <DictSelect
                                v-model="queryParams.collegeCode"
                                :data="options.college"
                                :clearable="true"
                                :filterable="true"
                                style="width: 100%;"
                            ></DictSelect>
                        </el-form-item>
                    </el-col> -->
                    <el-col :span="8">
                        <el-form-item label="辅修年级">
                            <el-date-picker
                                v-model="queryParams.grade"
                                value-format="yyyy"
                                type="year"
                                clearable
                                :placeholder="$t('message.plsSelect')"
                                style="width: 100%"
                            />
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="8">
                        <el-form-item :label="$t('minor.course.advancedLevel')">
                            <DictSelect
                                v-model="queryParams.advancedLevel"
                                :data="options.advancedLevel"
                                clearable
                                style="width:100%;"
                            ></DictSelect>
                        </el-form-item>
                    </el-col> -->
                    <el-col :span="8">
                        <el-form-item :label="$t('minor.culture.publishStatus')">
                            <DictSelect
                                v-model="queryParams.status"
                                :data="options.cultureStatus"
                                clearable
                                style="width:100%;"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                </el-row>
            </condition-card>
            <el-card shadow="never">
                <div class="first_title">{{$t('minor.culture.cultureListTile')}}</div>
                <div class="btn">
                    <el-button
                        type="danger"
                        @click="deleteCultureTemplate"
                        v-if="!btnStatus"
                    >{{$t('minor.culture.deleteBtn')}}</el-button>
                    <el-button
                        type="primary"
                        @click="publishCultureTemplate"
                        v-if="!btnStatus"
                    >{{$t('minor.culture.publishBtn')}}</el-button>
                    <el-button type="primary" @click="copy">复制</el-button>
                    <el-button
                        type="primary"
                        @click="addCultureTemplateInfo"
                        v-if="!btnStatus"
                    >{{$t('minor.course.addBtn')}}</el-button>
                </div>
                <EduTable
                    :selection="true"
                    @page-change="pageChange"
                    :data="tableData.list"
                    :total="tableData.total_"
                    @selection-change="chooseRow"
                    :pageSize="pageSize"
                    :pageNum="pageNum"
                >
                    <el-table-column
                        show-overflow-tooltip
                        :label="$t('minor.culture.templateNameCn')"
                    >
                        <template slot-scope="scope">
                             <el-button
                                type="text"
                                @click="previewTemp(scope.row)"
                                size="mini"
                            >{{scope.row.name}}</el-button>
                        </template>
                    </el-table-column>
                    <el-table-column
                        show-overflow-tooltip
                        :label="$t('minor.culture.templateNameEn')"
                    >
                        <template slot-scope="scope">{{scope.row.nameEn}}</template>
                    </el-table-column>
                    <!-- <el-table-column show-overflow-tooltip :label="$t('minor.major.college')">
                        <template slot-scope="scope">{{scope.row.collegeName}}</template>
                    </el-table-column> -->
                    <el-table-column show-overflow-tooltip :label="$t('辅修年级')">
                        <template slot-scope="scope">{{scope.row.minorGrade}}</template>
                    </el-table-column>
                    <!-- <el-table-column
                        show-overflow-tooltip
                        :label="$t('minor.course.advancedLevel')"
                    >
                        <template slot-scope="scope">{{scope.row.advancedLevelName}}</template>
                    </el-table-column> -->
                    <el-table-column
                        show-overflow-tooltip
                        :label="$t('minor.culture.publishStatus')"
                    >
                        <template slot-scope="scope">
                            <el-tag
                                :type="scope.row.status === 1 ? 'success' : 'info'"
                                size="mini"
                                disable-transitions
                            >{{ getPushLable(scope.row.status) }}</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column show-overflow-tooltip :label="$t('message.operating')">
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                @click="viewTemplate(scope.row)"
                                v-if="scope.row.status == '1'"
                                size="mini"
                            >{{$t('minor.course.viewBtn')}}</el-button>
                            <el-button
                                type="text"
                                @click="editlTemplate(scope.row)"
                                v-if="scope.row.status == '0' && !btnStatus"
                                size="mini"
                            >{{$t('minor.course.editBtn')}}</el-button>
                            <el-button
                                type="text"
                                @click="deleteTemplate(scope.row)"
                                v-if="scope.row.status == '0' && !btnStatus"
                                size="mini"
                            >{{$t('minor.course.deleteBtn')}}</el-button>
                            <el-button
                                type="text"
                                @click="revokeTemplate(scope.row)"
                                v-if="scope.row.status == '1' && !btnStatus"
                                size="mini"
                            >{{$t('minor.culture.repealBtn')}}</el-button>
                        </template>
                    </el-table-column>
                </EduTable>
            </el-card>
        </div>
        <div v-if="key !='cultureList' &&  key != 'catChapter'" style="margin: 4px 4px 16px;">
            <el-card shadow="never">
                <div class="stepstyle">
                    <el-steps :active="defaultValue" align-center>
                        <el-step title="基础信息"></el-step>
                        <el-step title="课程性质"></el-step>
                        <el-step title="课程设置"></el-step>
                        <el-step title="章节设置"></el-step>
                    </el-steps>
                </div>
            </el-card>
        </div>
        <!-- <div class="edu-page-title" v-if="key !='cultureList' &&  key != 'catChapter'">
            <span
                v-for="(item, index) in topNavItems"
                :class="{active: item.value == key}"
                :key="index"
                class="border-right"
                @click="clickItem(item, index)"
            >{{ item.label }}</span>
        </div> -->
        <div class="edu-page-warp" v-if="key=='addCultureTemplate'">
            <el-card shadow="never" v-if="!viewFlag">
                <div class="parentDiv">
                    <div class="templateFont">新增方案</div>
                </div>
                <el-form
                    :model="createbasicForm"
                    ref="createbasicForm"
                    label-width="100px"
                    :rules="basicRules"
                >
                    <el-row>
                         <!-- <el-col :span="8">
                            <el-form-item>
                                <el-checkbox v-model="templateForm.checked">自动命名</el-checkbox>
                            </el-form-item>ming
                        </el-col>  -->
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="模板名称" prop="templateName">
                                <el-input
                                    ref="templateName"
                                    v-model="createbasicForm.templateName"
                                    placeholder="请输入"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="英文名称">
                                <el-input v-model="createbasicForm.templateNameEn"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <!-- <el-form-item :label="$t('minor.major.college')" prop="collegeCode">
                                <DictSelect
                                    v-model="createbasicForm.collegeCode"
                                    :data="options.college"
                                    :clearable="true"
                                    :filterable="true"
                                    style="width: 100%;"
                                ></DictSelect>
                            </el-form-item> -->
                            <el-form-item label="辅修年级" prop="minorGrade">
                                <el-date-picker
                                    v-model="createbasicForm.minorGrade"
                                    value-format="yyyy"
                                    type="year"
                                    clearable
                                    :placeholder="$t('message.plsSelect')"
                                    style="width: 100%"
                                />
                            </el-form-item>
                        </el-col>
                        <!-- <el-col :span="8">
                            <el-form-item
                                :label="$t('minor.course.advancedLevel')"
                                prop="advancedLevel"
                            >
                                <DictSelect
                                    v-model="createbasicForm.advancedLevel"
                                    :data="options.advancedLevel"
                                    clearable
                                    style="width:100%;"
                                ></DictSelect>
                            </el-form-item>
                        </el-col> -->
                        <el-col :span="8">
                            <el-form-item
                                label="学期数"
                                prop="schoolTerm"
                            >
                                <el-input-number v-model="createbasicForm.schoolTerm" controls-position="right" :min="1" :max="20" style="width: 100%;"></el-input-number>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
            </el-card>
            <el-card shadow="never">
                <div class="templateFont">章节划分</div>
                <div class="sectionBtn" v-if="!viewFlag">
                    <el-button type="primary" @click="addsectionInfo">{{$t('minor.course.addBtn')}}</el-button>
                </div>
                <EduTable :pagination="false" :data="sectionData.list">
                    <el-table-column min-width="200" show-overflow-tooltip label="章节名称">
                        <template slot-scope="scope">
                            <el-input v-if="scope.row.isShow" v-model="scope.row.sectionName"></el-input>
                            <span v-else>{{scope.row.sectionName}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column min-width="200" show-overflow-tooltip label="英文名称">
                        <template slot-scope="scope">
                            <el-input v-if="scope.row.isShow" v-model="scope.row.sectionNameEn"></el-input>
                            <span v-else>{{scope.row.sectionNameEn}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column min-width="200" label="内容导入方式">
                        <template slot-scope="scope">
                            <el-select
                                filterable
                                :disabled="scope.row.disabledFlag"
                                style="width: 100%"
                                v-model="scope.row.contentWay"
                            >
                                <el-option
                                    v-for="item in options.contentWay"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </template>
                    </el-table-column>
                    <el-table-column
                        min-width="200"
                        show-overflow-tooltip
                        v-if="!viewFlag"
                        :label="$t('message.operating')"
                    >
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                @click="cancelRecord(scope.row,scope.$index)"
                                v-if="scope.row.isShow"
                                size="mini"
                            >取消</el-button>
                            <el-button
                                type="text"
                                v-if="!scope.row.isShow"
                                @click="editlRecord(scope.row)"
                                size="mini"
                            >{{$t('message.edit')}}</el-button>
                            <el-button
                                type="text"
                                @click="deleteRecord(scope.$index,scope.row)"
                                size="mini"
                            >{{$t('message.delete')}}</el-button>
                            <el-button
                                type="text"
                                @click="saveRecord(scope.row)"
                                size="mini"
                                v-if="scope.row.isShow"
                            >保存</el-button>
                            <el-button
                                type="text"
                                @click="moveUpRecord(scope.$index,scope.row)"
                                size="mini"
                                v-if="!scope.row.isShow && scope.$index !=0"
                            >上移</el-button>
                            <el-button
                                type="text"
                                @click="moveDownRecord(scope.$index,scope.row)"
                                size="mini"
                                v-if="!scope.row.isShow  && scope.$index!=sectionData.list.length-1"
                            >下移</el-button>
                        </template>
                    </el-table-column>
                </EduTable>
            </el-card>
        </div>
        <div class="edu-page-warp" v-if="key=='addCourseType'">
            <el-card shadow="never">
                <div v-if="!viewFlag" class="edu-opertion-bar">
                    <!-- <div class="float-left"/> -->
                    <div class="float-right">
                        <el-button
                            @click="addCourseCategory"
                            type="primary"
                        >{{ $t('common.btn.add') }}</el-button>
                    </div>
                </div>
                <course-category  :show.sync="courseCategoryShow" :templateId="templateId" @init="initCourseTypeData" v-if="courseCategoryShow"/>
                <!-- <i class="el-icon-warning-outline"></i> -->
                <div class="tip-message">"课程类别" 会自动关联到相应学生,请填写每个课程类别的最低学分要求</div>
                <div>
                    <el-table
                        :data="courseTyleData.list"
                        border
                        :span-method="objectSpanMethod"
                        :row-style="rowStyle"
                        :header-cell-style="rowClass"
                    >
                        <el-table-column min-width="200px" show-overflow-tooltip label="课程性质" align="center">
                            <template slot-scope="scope">{{scope.row.courseTypeName}}</template>
                        </el-table-column>
                        <el-table-column min-width="200px" show-overflow-tooltip label="课程子性质" align="center" v-if="showCourseSubNature">
                            <template slot-scope="scope">
                                {{scope.row.courseName}}
                            </template>
                        </el-table-column>
                        <el-table-column min-width="200px" show-overflow-tooltip label="课程学分要求" align="center">
                            <template slot-scope="scope">
                                <span v-if="viewFlag" style="width:80px;">{{scope.row.credits}}</span>
                                <el-input
                                    type="number"
                                    v-if="!viewFlag && !scope.row.isTotal"
                                    v-model="scope.row.credits"
                                    @blur="autoCalculate"
                                    style="width:80px;"
                                ></el-input>
                                <span v-if="!viewFlag && scope.row.isTotal">{{scope.row.credits}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column min-width="200px" show-overflow-tooltip label="百分比" align="center">
                            <template slot-scope="scope">{{scope.row.percent}}</template>
                        </el-table-column>
                        <el-table-column label="操作" align="center" v-if="!viewFlag">
                            <template slot-scope="scope">
                                <el-button type="text" size="mini" v-if="!scope.row.isTotal" @click="removeCourse(scope.row.id)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
            </el-card>
        </div>
        <div class="edu-page-warp" v-if="key=='addCourseSet'">
            <el-card shadow="never">
                <minor-table @selectChange="handelSelect" :templateId="templateId" :operationFlag="!viewFlag" :schoolTerm="createbasicForm.schoolTerm"/>
            </el-card>
        </div>
        <div class="edu-page-warp" v-if="key=='addChapterSet'">
            <el-card shadow="never">
                <chapter-set
                    v-if="!viewFlag"
                    ref="chapterSet"
                    :courseTyleData="courseTyleData.list"
                    :templateId="templateId"
                    :schoolTerm="createbasicForm.schoolTerm"
                    @tableClick="tableClick"
                    @saveSuccess="saveSuccess"
                />
                <cat-chapter
                    v-else 
                    ref="catChapter"
                    :courseTyleData="courseTyleData.list"
                    :templateId="templateId"
                    :title="templateTitle"
                    :schoolTerm="createbasicForm.schoolTerm"
                    @goBack="goBack"
                />
            </el-card>
        </div>

        <div class="edu-page-warp" v-if="key=='catChapter'">
            <cat-chapter
                ref="catChapter"
                :courseTyleData="courseTyleData.list"
                :templateId="templateId"
                :schoolTerm="createbasicForm.schoolTerm"
                :title="templateTitle"
                @goBack="goBack"
            />
        </div>

        <div class="edu-page-warp" v-if="key=='relationTable'">
            <relation-table
                ref="relationTable"
                :templateId="templateId"
                :data="relationTableData"
                :showCourseSubNature="showCourseSubNature"
                :schoolTerm="createbasicForm.schoolTerm"
                :courseTyleData="courseTyleData.list"
                @relationTableSaved="relationCancel"
            />
        </div>
        <div class="bottomDiv" v-if="defaultValue && key != 'catChapter'">
            <el-button  @click="returnCultureList" v-if="key !='relationTable' && !(viewFlag && defaultValue == 4)">返回</el-button>
            <el-button type="primary" @click="nextStep('decrease')" v-if="defaultValue!==1 && key !=='relationTable'">上一步</el-button>
            <el-button type="primary" @click="save" v-if="!viewFlag && key !=='relationTable'">保存</el-button>
            <el-button type="primary" @click="nextStep('increase')" v-if="defaultValue!==4 && key !=='relationTable'">下一步</el-button>
            <el-button type="primary" @click="catChapter" v-if="defaultValue==4 && !viewFlag && key !=='relationTable'">预览</el-button>
            <el-button type="primary" @click="returnList" v-if="defaultValue==4 && !viewFlag && key !=='relationTable'">完成</el-button>
            <template v-if="defaultValue == 4 && key =='relationTable' && !viewFlag">
                <el-button @click="relationCancel">取消</el-button>
                <el-button type="primary" @click="relationOk">确定</el-button>
            </template>
        </div>
        <el-dialog
            :visible.sync="copyVisible"
            title="复制微专业培养方案模板"
            width="35%"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
        >
            <el-form ref="year" :model="copyForm" inline>
                <el-form-item
                    :rules="[
            { required: true, message: $t('minor.tip.minorGradeSelectTip')}
          ]"
                    :label="$t('minor.major.minorGrade')+':'"
                    prop="year"
                >
                    <el-select v-model="copyForm.year" placeholder="请选择" clearable>
                        <el-option
                            v-for="item in options.grade"
                            :key="item.value"
                            :label="item.label + '级'"
                            :value="item.value"
                        />
                    </el-select>
                </el-form-item>
                <el-form-item v-if="!!copyForm.year">
                    <i class="el-icon-warning"></i>
                    <span>选择辅修年级将会生成该辅修年级新的模板</span>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="resetCopy('year')">取 消</el-button>
                <el-button type="primary" @click="copyOk('year')">保存</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import UTILS from "common/src/utils/utils";
import { queryDic } from "common/src/api/dictionary";
import { getSessionUser } from "common/src/api/session";
import { getValue } from "common/src/api/commonParam";
import { queryAdvancedLevel } from "common/src/api/minor/collegemajor";
import {
    queryMinorCultureTemplateList,
    batchDeleteTemplate,
    saveTemplateInfo,
    queryTemplateInfo,
    batchPublishTemplate,
    saveCourseTypeInfo,
    revokeTemplate,
    copyMinorCultureTemplate
} from "common/src/api/minor/minorCultureTemplate";
import { queryCourseTypeList } from "common/src/api/minor/minorCulturePlanManager";
import {deleteMinorCoursesLabeById} from "common/src/api/minor/minorCultureTemplate";
export default {
    components: {
        courseCategory: resolve => require(['./courseCategory'], resolve),
        MinorTable: resolve => require(['../component/MinorTable'], resolve),
        ChapterSet: resolve => require(['../component/ChapterSet'], resolve),
        SchemeCheck: resolve => require(['../component/SchemeCheck'], resolve),
        RelationTable: resolve => require(['../component/RelationTable'], resolve),
        CatChapter: resolve => require(['../component/CatChapter'], resolve)
    },
    props: {
        isRead: {
            default: false //操作列是否可见
        },
        dataType: {
            default: "1" //1为模板，2为方案
        },
        inChange: {
            type: Boolean,
            default: false
        }
    },
    data() {
        return {
            viewFlag: false,
            chapterSaved: false,
            relationTableData: null,
            editFlag: false,
            isSaved: false,
            key: "cultureList",
            spanDataForModule: [],
            panDataForGroup: [],
            defaultValue: 0,
            templateId: 0,
            optionType: 0, // 0 新增 1 编辑 2 查看
            tableData: {},
            chooseRows: [],
            templateIds: [],
            courseTables: [],
            collegeName: "",
            gradeNum: '',
            advancedLevelName: "",
            sectionTableNum: 0,
            sectionData: {
                list: []
            },
            pageSize: 20,
            btnStatus: true,
            pageNum: 1,
            chapterData: "",
            semesterSorts: [
                "一",
                "二",
                "三",
                "四",
                "五",
                "六",
                // "七",
                // "八",
                // "九",
                // "十"
            ],
            courseTyleData: {
                list: []
            },
            templateForm: {
                checked: false
            },
            createbasicForm: {
                minorGrade: '',
                templateName: "",
                templateNameEn: "",
                collegeCode: "",
                advancedLevel: "",
                schoolTerm: 6
            },
            queryParams: {
                grade: '',
                collegeCode: "",
                advancedLevel: "",
                status: ""
            },
            options: {
                advancedLevel: [],
                college: [],
                cultureStatus: [
                    { label: "草稿", value: "0" },
                    { label: "已发布", value: "1" }
                ],
                contentWay: [
                    { label: "直接输入", value: "0" },
                    { label: "系统表格", value: "1" }
                ],
                pushStatus: [
                    { label: "草稿", value: 0 },
                    { label: "已发布", value: 1 }
                ],
                grade: []
            },
            basicRules: {
                templateName: [
                    {
                        required: true,
                        message: this.$t(
                            "minor.culturePlan.templateNameNotNull"
                        ),
                        trigger: "blur"
                    }
                ],
                // collegeCode: [
                //     {
                //         required: true,
                //         message: this.$t("minor.culturePlan.collegeNotNull"),
                //         trigger: "change"
                //     }
                // ],
                minorGrade: [
                    {
                        required: true,
                        message: this.$t("辅修年级不能为空"),
                        trigger: "change"
                    }
                ],
                // advancedLevel: [
                //     {
                //         required: true,
                //         message: this.$t(
                //             "minor.culturePlan.advancedLevelNotNull"
                //         ),
                //         trigger: "change"
                //     }
                // ]
            },
            topNavItems: [
                {
                    label: "基础信息",
                    index: 0,
                    value: 'addCultureTemplate',
                    active: true
                },
                {
                    label: "课程类别",
                    index: 1,
                    value: 'addCourseType',
                    active: false
                },
                {
                    label: "课程设置",
                    index: 2,
                    value: 'addCourseSet',
                    active: false
                },
                {
                    label: "章节设置",
                    index: 3,
                    value: 'addChapterSet',
                    active: false
                }
            ],
            copyForm: {
                year: "",
                idSet: []
            },
            copyVisible: false,
            courseCategoryShow: false,
            showCourseSubNature: false //显示课程子性质
        };
    },
    mounted() {
        if (!this.$checkMinor()) return;
        this.getOptions();
        this.initCultureTemplateList();
        this.initData();
        this.getType();
    },
    watch: {
        // "createbasicForm.collegeCode": function(val) {
        //     if (this.templateForm.checked) {
        //         var obj = {};
        //         let connector = "/";
        //         if (val == "") {
        //             this.collegeName = "";
        //             connector = "";
        //         } else {
        //             obj = this.options.college.find(function(item) {
        //                 return item.value === val;
        //             });
        //             this.collegeName = obj.label;
        //         }

        //         this.createbasicForm.templateName =
        //             (this.collegeName && this.collegeName) +
        //             connector +
        //             (this.advancedLevelName && this.advancedLevelName);
        //         this.$refs.templateName.focus();
        //     }
        // },
        "createbasicForm.minorGrade": function(val) {
            if (this.templateForm.checked) {
                var obj = {};
                let connector = "/";
                if (!val) {
                    this.gradeNum = "";
                    connector = "";
                } else {
                    this.gradeNum = val;
                }

                this.createbasicForm.templateName =
                    (this.gradeNum && this.gradeNum) +
                    connector +
                    (this.advancedLevelName && this.advancedLevelName);
                this.$refs.templateName.focus();
            }
        },
        "createbasicForm.advancedLevel": function(val) {
            if (this.templateForm.checked) {
                var obj = {};
                let connector = "/";
                if (val == "") {
                    this.advancedLevelName = "";
                    connector = "";
                } else {
                    obj = this.options.advancedLevel.find(function(item) {
                        return item.value === val;
                    });
                    this.advancedLevelName = obj.label;
                }

                this.createbasicForm.templateName =
                    // (this.collegeName && this.collegeName) +
                    (this.gradeNum && this.gradeNum) +
                    connector +
                    (this.advancedLevelName && this.advancedLevelName);
                this.$refs.templateName.focus();
            }
        }
    },
    methods: {
        //获取当前登录角色权限信息
        getType() {
            getSessionUser().then(res => {
                if ((res.code = 200)) {
                    if (!res.data.mockUser) {
                        if (res.data.user.type == 2) {
                            //学生
                            this.btnStatus = true;
                        } else if (
                            res.data.user.innerRoles.join(",").indexOf("1") >=
                                0 &&
                            res.data.user.currentRole == "1"
                        ) {
                            //校管理员登录，放开审核操作
                            this.btnStatus = false;
                            this.initAdvancedLevel("0");
                        } else if (
                            res.data.user.innerRoles.join(",").indexOf("2") >=
                                0 &&
                            res.data.user.innerRoles.join(",").indexOf("1") ==
                                -1 &&
                            res.data.user.currentRole == "1"
                        ) {
                            //学院教务登录，放开审核操作
                            this.btnStatus = true;
                            this.initAdvancedLevel("0");
                        }
                    } else {
                        if (
                            !!res.data.mockUser &&
                            res.data.mockUser.type == 2
                        ) {
                            //学生
                            this.btnStatus = true;
                        } else if (
                            !!res.data.mockUser &&
                            res.data.mockUser.innerRoles
                                .join(",")
                                .indexOf("1") >= 0 &&
                            res.data.mockUser.currentRole == "1"
                        ) {
                            //校管理员登录，放开审核操作
                            this.btnStatus = false;
                            this.initAdvancedLevel("0");
                        } else if (
                            !!res.data.mockUser &&
                            res.data.mockUser.innerRoles
                                .join(",")
                                .indexOf("2") >= 0 &&
                            res.data.mockUser.innerRoles
                                .join(",")
                                .indexOf("1") == -1 &&
                            res.data.mockUser.currentRole == "1"
                        ) {
                            //学院教务登录，放开审核操作
                            this.btnStatus = true;
                            this.initAdvancedLevel("0");
                        }
                    }
                }
            });
        },
        //合并单元格
        arraySpanMethod({ row, column, rowIndex, columnIndex }) {
            if (row.isCategoryRow) {
                return {
                    rowspan: 1,
                    colspan: this.isRead ? 21 : 22 //根据操作列是否可见，计算课程分类合并列
                };
            }
            if (columnIndex == 1 || columnIndex == 9) {
                let spanData =
                    columnIndex == 1
                        ? this.spanDataForModule
                        : this.spanDataForGroup;
                let d = spanData.filter(ele => {
                    return ele.rowIndex == rowIndex;
                });
                if (d.length > 0) {
                    return {
                        rowspan: d[0].rowspan,
                        colspan: 1
                    };
                }
            }
        },
        initCourseTypeData() {
            this.courseTyleData.list = [];
            this.cultureRuleListCopy = [];
            //初始化课程类别
            let params = {
                id: this.templateId,
                type: 1 //表示 1 模板 2 方案
            };
            queryCourseTypeList(params).then(res => {
                if (res.code == 200) {
                    let list = [];
                    let cultureRuleList =  res.data && res.data.cultureRuleList || [];
                    this.cultureRuleListCopy = _.cloneDeep(cultureRuleList);
                    let par =  cultureRuleList.filter( item =>  !Number(item.parentId));
                    this.showCourseSubNature = false; //是否显示子性质
                    par.forEach(p =>{
                        let children = [];
                        let isFirst = true;
                        cultureRuleList.forEach(e => {
                            if (p.labelId == e.parentId){
                                children.push({
                                    id: e.id,
                                    labelId: e.labelId,                              
                                    courseTypeName: p.label,
                                    courseName: e.label,
                                    credits: e.credit || 0,
                                    percent: "0%",
                                    isFirst
                                });
                                isFirst = false;
                            }
                        });
                        if (!children.length) {
                            list.push({
                                id: p.id,
                                labelId: p.labelId,
                                courseName: '',
                                courseTypeName: p.label,
                                credits: p.credit || 0,
                                percent: "0%",
                                isFirst: true,
                                len: 1
                            });
                        }else {
                            this.showCourseSubNature = true;
                            children[0].len = children.length;
                            list = [...list, ...children]
                        }
                    })
                    list.push({
                        courseTypeName: "总计",
                        credits: 0,
                        percent: "0%",
                        isTotal: true
                    });
                    this.courseTyleData.list = [...list];
                    this.autoCalculate();
                }
            });
        },
        initCultureTemplateList() {
            if (!this.$checkMinor()) return;
            let params = {
                pageNum_: this.pageNum,
                pageSize_: this.pageSize,
                // collegeCode: this.queryParams.collegeCode,
                minorGrade: this.queryParams.grade,
                advanceLevelCode: this.queryParams.advancedLevel,
                status: this.queryParams.status,
                projId: 1
            };
            queryMinorCultureTemplateList(params).then(res => {
                if (res.code == 200) {
                    this.tableData = res.data;
                }
            });
        },
        getOptions() {
            //筛选条件字典查询
            const data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: ["X_YX"]
            };
            queryDic(data).then(res => {
                this.options.college = [];
                UTILS.fillSelect(
                    {
                        college: "X_YX"
                    },
                    res.data,
                    this.options
                );
            });
        },
        initAdvancedLevel(isOnCampus) {
            let params = {
                isOnCampus: isOnCampus
            };
            this.options["advancedLevel"] = [];
            queryAdvancedLevel(params).then(res => {
                if (res.code == 200) {
                    for (let key = 0; key < res.data.length; key++) {
                        this.options["advancedLevel"].push({
                            value: res.data[key].advancedLevelCode,
                            label: res.data[key].advancedLevelName
                        });
                    }
                }
            });
        },
        rowStyle({ row, rowIndex }) {
            return "text-align:center;";
        },
        rowClass({ row, rowIndex }) {
            return "text-align:center;";
        },
        resetQuery() {
            this.queryParams = {
                collegeCode: "",
                advancedLevel: "",
                status: "",
                grade: ''
            };
            this.initCultureTemplateList();
        },
        addCultureTemplateInfo() {
            if (!this.$checkMinor()) return;
            this.templateId = 0;
            this.viewFlag = false;
            this.optionType = 0;
            this.defaultValue = 1;
            this.key = "addCultureTemplate";
            this.sectionData.list = [];
            this.createbasicForm = {
                templateName: "",
                templateNameEn: "",
                minorGrade: "",
                advancedLevel: "",
                schoolTerm: 6,
            };
        },
        breadcrumbChange(val) {
            if (val === "cultureList") {
                this.defaultValue = 0;
                this.editFlag = false;
                this.initCultureTemplateList();
            }
        },
        //表格复选框选中或取消
        saveSuccess(payload, flag) {
            this.chapterSaved = payload;
            if (this.chapterSaved && flag== true) {
                this.key = "cultureList";
                this.defaultValue = 0;
                this.initCultureTemplateList();
            }
        },
        chooseRow(val) {
            this.chooseRows = val;
        },
        tableClick(val) {
            this.relationTableData = val;
            this.key = "relationTable";
        },
        nextStep(value) {
            if (value == "increase") {
                this.defaultValue++;
            } else {
                this.defaultValue--;
            }
            switch(this.defaultValue) {
                case 1: 
                    this.key = "addCultureTemplate";
                    break;
                case 2:
                    this.saveCourseType(value);
                    break;
                case 3:
                    this.saveCourseSet(value);
                    break;
                case 4:
                    if (this.isNext) {
                        this.key = "addChapterSet";
                        this.chapterSaved = false;
                    } else {
                        if (this.addCourseWrongTip) {
                            this.$message.warning(this.addCourseWrongTip);
                        }
                        this.defaultValue--;
                    }
                    break;
                default:
                    this.key = "addCultureTemplate";
            }





            // if (!this.editFlag) {
            //     if (!this.templateId) {
            //         this.$message.warning("请先保存");
            //         return;
            //     }
            //     if (
            //         value == "increase" &&
            //         !this.isSaved &&
            //         this.defaultValue == 2
            //     ) {
            //         this.$message.warning("请先保存");
            //         return;
            //     }
            // }
            // if (value == "increase") {
            //     this.defaultValue++;
            // } else {
            //     this.defaultValue--;
            // }
            // switch (this.defaultValue) {
            //     case 1:
            //         this.key = "addCultureTemplate";
            //         break;
            //     case 2:
            //         if (this.optionType != 2) {
            //             if (this.checkSectionInfo()) {
            //                 this.initCourseTypeData();
            //             } else {
            //                 this.defaultValue--;
            //             }
            //             if (value == "increase") {
            //                 this.saveTemplateInfo()
            //                     .then(res => {
            //                         this.key = "addCourseType";
            //                     })
            //                     .catch(res => {
            //                         this.defaultValue--;
            //                         console.log(res);
            //                     });
            //             } else {
            //                 this.key = "addCourseType";
            //             }
            //         } else {
            //             this.key = "addCourseType";
            //             this.initCourseTypeData();
            //         }
            //         break;
            //     case 3:
            //         if (value == "increase") this.saveCourseTypeInfo();
            //         this.key = "addCourseSet";
            //         break;
            //     case 4:
            //         this.key = "addChapterSet";
            //         break;
            //     default:
            //         this.key = "addCultureTemplate";
            // }
        },
        saveCourseType(value) {
            if (this.optionType != 2) {
                if (value == "increase") {
                    this.$refs.createbasicForm.validate(valid => {
                        if (!valid) {
                            this.defaultValue--;
                        } else if (!this.checkSectionInfo()) {
                            this.$message.error("章节名称不能为空");
                            this.defaultValue--;
                        } else {
                            this.saveTemplateInfo()
                                .then(res => {
                                    this.key = "addCourseType";
                                    this.initCourseTypeData();
                                })
                                .catch(res => {
                                    this.defaultValue--;
                                });
                        }
                    })
                } else {
                    this.key = "addCourseType";
                    if(this.optionType == 1){
                        this.initCourseTypeData();
                    }
                }
            } else {
                this.key = "addCourseType";
                this.initCourseTypeData();
            }
        },
        saveCourseSet(value) {
            if (this.optionType == 2) { 
                this.key = "addCourseSet";
                return;
            }
            if (value == "increase") {
                if (this.checkIsWrong()) {
                    this.defaultValue--;
                    return;
                }else {
                    this.saveCourseTypeInfo();
                    this.key = "addCourseSet";
                }
            } else {
                this.key = "addCourseSet";
            }
        },
        //删除章节
        deleteRecord(index, row) {
            this.sectionData.list.splice(index, 1);
            if (this.sectionTableNum >= 1) {
                this.sectionTableNum--;
            }
            this.chapterData = JSON.stringify(this.sectionData.list);
        },
        cancelRecord(row, index) {
            this.sectionData.list = JSON.parse(this.chapterData);
            this.sectionData.list[index].isShow = false;
            this.sectionData.list[index].disabledFlag = true;
            this.chapterData = JSON.stringify(this.sectionData.list);
        },
        //添加章节
        addsectionInfo() {
            this.sectionData.list.push({
                isShow: true,
                disabledFlag: false,
                sectionId: "",
                sectionName: "",
                sectionNameEn: "",
                contentWay: "0"
            });
            this.chapterData = JSON.stringify(this.sectionData.list);
        },
        //保存章节
        saveRecord(row) {
            //校验章节名称不为空
            if (!row.sectionName) {
                this.$message.error({
                    type: "info",
                    message: "章节名称不能为空"
                });
            } 
            // else if (!row.sectionNameEn) {
            //     this.$message.error({
            //         type: "info",
            //         message: "英文名称不能为空"
            //     });
            // } 
            else {
                this.chapterData = JSON.stringify(this.sectionData.list);
                row.isShow = false;
                row.disabledFlag = true;
                this.sectionTableNum++;
            }
        },
        getSelectRows() {
            this.chooseRows.length > 0 &&
                this.chooseRows.forEach(e => {
                    if (e.id != null) {
                        this.templateIds.push(e.id);
                    }
                });
        },
        //校验章节信息
        checkSectionInfo() {
            let flag = true;
            this.sectionData.list &&
                this.sectionData.list.forEach(e => {
                    if (!e.sectionName) { //|| !e.sectionNameEn
                        flag = false;
                        return;
                    }
                });
            return flag;
        },
        //编辑章节
        editlRecord(row) {
            this.editFlag = true;
            if (this.sectionTableNum >= 1) {
                this.sectionTableNum--;
            }
            row.isShow = true;
            row.disabledFlag = false;
        },
        //章节上移
        moveUpRecord(index, row) {
            if (index > 0) {
                let upData = this.sectionData.list[index - 1];
                this.sectionData.list.splice(index - 1, 1);
                this.sectionData.list.splice(index, 0, upData);
            }
        },
        //章节下移
        moveDownRecord(index, row) {
            if (!(index + 1 === this.sectionData.list.length)) {
                let downData = this.sectionData.list[index + 1];
                this.sectionData.list.splice(index + 1, 1);
                this.sectionData.list.splice(index, 0, downData);
            }
        },
        //初始化数据
        initData() {},
        getPushLable(value) {
            const pushStatu = this.options.pushStatus.find(
                t => t.value === value
            );
            if (pushStatu === "{}") {
                return value;
            } else {
                return pushStatu.label;
            }
        },
        //删除培养方案模板
        deleteCultureTemplate() {
            this.templateIds = [];
            this.getSelectRows();
            if (this.templateIds.length == 0) {
                this.$message({
                    type: "warning",
                    message: "请至少选择一条数据"
                });
                return;
            }
            let params = {
                idSet: this.templateIds
            };
            this.$eduConfirm("您确定要删除吗？", "删除", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(() => {
                    batchDeleteTemplate(params).then(res => {
                        if (res.code == 200) {
                            this.$message({
                                type: "success",
                                message: "删除成功!"
                            });
                            this.initCultureTemplateList();
                        }
                    });
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消删除"
                    });
                });
        },
        deleteTemplate(row) {
            let params = {
                idSet: row.id
            };
            this.$confirm("您确定要删除吗？", "删除", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(() => {
                    batchDeleteTemplate(params).then(res => {
                        if (res.code == 200) {
                            this.$message({
                                type: "success",
                                message: "删除成功!"
                            });
                            this.initCultureTemplateList();
                        }
                    });
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消删除"
                    });
                });
        },
        publishCultureTemplate() {
            this.templateIds = [];
            this.getSelectRows();
            if (this.templateIds.length == 0) {
                this.$message({
                    type: "warning",
                    message: "请至少选择一条数据"
                });
                return;
            }
            let params = {
                idSet: this.templateIds
            };
            this.$eduConfirm("您确定要发布吗？", "发布", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(() => {
                    batchPublishTemplate(params).then(res => {
                        if (res.code == 200) {
                            this.$message({
                                type: "success",
                                message: "发布成功!"
                            });
                            this.initCultureTemplateList();
                        }
                    });
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消发布"
                    });
                });
        },
        catChapter() {
            this.key = "catChapter";
        },
        goBack() {
            if (this.viewFlag) {
                this.defaultValue = 0;
                this.key = "cultureList";
                this.initCultureTemplateList();
            } else {
                this.key = "addChapterSet";
            }
        },
        save() {
            if (this.key === "addCultureTemplate") {
                this.saveTemplateInfo();
            } else if (this.key === "addCourseType") {
                this.saveCourseTypeInfo();
            } else if (this.key === "relationTable") {
                this.$refs.relationTable.saveTableDetail();
            } else if (this.key === "addChapterSet") {
                this.$refs.chapterSet.saveChapter();
            }else if (this.key == 'addCourseSet') {
                this.$message({
                    type: "success",
                    message: "保存成功"
                });
            }
        },
        //校验英文名称只能是字母、数字或者空格
        checkNameEn(value) {
            if (
                value &&
                value.toString().replace(/^[a-zA-Z\d\s]*$/, "") != ""
            ) {
                this.$message.error(this.$t("minor.tip.englishNameError"));
                return false;
            } else {
                return true;
            }
        },
        saveTemplateInfo() {
            return new Promise((resolve, reject) => {
                if (!this.$refs.createbasicForm) return false;
                this.$refs.createbasicForm.validate(valid => {
                    if (valid) {
                        //校验英文名称
                        if (
                            !this.checkNameEn( this.createbasicForm.templateNameEn )
                        ) {
                            reject();
                            return;
                        }
                        if (this.checkSectionInfo()) {
                            //获取章节信息
                            let sectionList = [];
                            this.sectionData.list &&
                                this.sectionData.list.forEach(e => {
                                    sectionList.push({
                                        id: e.sectionId,
                                        name: e.sectionName,
                                        nameEn: e.sectionNameEn,
                                        sortNo:
                                            this.sectionData.list.indexOf(e) +
                                            1,
                                        contentImportType: e.contentWay,
                                        font: "黑体",
                                        fontSize: 18
                                    });
                                });
                            let params = {
                                projId: "1",
                                id:
                                    this.templateId != 0
                                        ? this.templateId
                                        : null,
                                name: this.createbasicForm.templateName,
                                nameEn: this.createbasicForm.templateNameEn,
                                advancedLevelCode: this.createbasicForm
                                    .advancedLevel,
                                minorGrade: this.createbasicForm.minorGrade,
                                schoolTerm: this.createbasicForm.schoolTerm,
                                // grade: this.createbasicForm.grade,
                                font: "黑体",
                                fontSize: 18,
                                sonCultureTemplateList: sectionList
                            };
                            saveTemplateInfo(params)
                                .then(res => {
                                    if (res.code == 200) {
                                        resolve(res);
                                        this.$message({
                                            message: "保存成功",
                                            type: "success"
                                        });
                                        this.templateId = res.data;
                                    } else {
                                        reject(res);
                                        this.$message.error(res.msg);
                                    }
                                })
                                .catch(res => {
                                    reject(res);
                                    this.$message.error(res.msg);
                                });
                        } else {
                            this.$message.error("章节名称不能为空");
                            return false;
                        }
                    } else {
                        return false;
                    }
                });
            });
        },
        returnCultureList() {
            //返回模板列表
            this.chooseRows = [];
            this.defaultValue = 0;
            this.templateForm.checked = false;
            this.key = "cultureList";
            this.initCultureTemplateList();
        },
        editlTemplate(row) {
            //编辑模板
            this.viewFlag = false;
            this.templateTitle = row.name;
            this.optionType = 1;
            this.templateId = row.id;
            this.key = "addCultureTemplate";
            this.sectionData.list = [];
            this.queryTemplateCultureList(row.id);
        },
        queryTemplateCultureList(id) {
            queryTemplateInfo(id).then(res => {
                if (res.code == 200) {
                    this.editFlag = true;
                    this.defaultValue = 1;
                    this.createbasicForm = {
                        templateName: res.data.name,
                        templateNameEn: res.data.nameEn,
                        minorGrade: res.data.minorGrade && (res.data.minorGrade + '') || '',
                        advancedLevel: res.data.advancedLevelCode,
                        schoolTerm: res.data.schoolTerm
                    };

                    res.data.sonCultureTemplateList &&
                        res.data.sonCultureTemplateList.forEach(e => {
                            this.sectionData.list.push({
                                isShow: false,
                                disabledFlag: true,
                                sectionId: e.id,
                                sectionName: e.name,
                                sectionNameEn: e.nameEn,
                                contentWay: e.contentImportType + ""
                            });
                        });
                    this.chapterData = JSON.stringify(this.sectionData.list);
                }
            });
        },
        calculatePercent(num, total) {
            //计算百分比
            num = parseFloat(num);
            total = parseFloat(total);
            if (isNaN(num) || isNaN(total)) {
                return "-";
            }
            return total <= 0
                ? "0%"
                : Math.round((num / total) * 10000) / 100.0 + "%";
        },
        //查询
        searchData() {
            this.editFlag = false;
            this.initCultureTemplateList();
        },
        autoCalculate() {
            let totalCredit = 0;
            //计算课程类别
            this.courseTyleData.list &&
                this.courseTyleData.list.forEach(e => {
                    if (!e.isTotal) {
                        totalCredit += Number(e.credits);
                    }
                });
            //计算百分比
            this.courseTyleData.list &&
                this.courseTyleData.list.forEach(e => {
                    if (e.isTotal) {
                        e.credits = totalCredit;
                    }
                    e.percent = this.calculatePercent(
                        Number(e.credits),
                        totalCredit
                    );
                });
        },
        checkIsWrong() {
            let flag = false;
            this.courseTyleData.list.forEach((el, index) => {
                if (!Number.isFinite(parseFloat(el.credits))) {
                    flag = true;
                }
            });
            if (flag) {
                this.$message.warning("学分输入有误，请核对后再进行保存");
            }
            return flag;
        },
        saveCourseTypeInfo() {
            if (this.checkIsWrong()) {
                return;
            }
            //获取章节信息
            let courseTypeList = [];
            this.cultureRuleListCopy && this.cultureRuleListCopy.forEach(e =>{
                    let par = {
                        id: e.id,
                        labelId: e.labelId,
                        credit: e.credit || 0,
                        taringingId: this.templateId,
                        parentId: e.parentId,
                        type: 1
                    }
                    let specItem = this.courseTyleData.list.find(item => item.labelId == e.labelId);
                    if (specItem) {
                        par.credit = specItem.credits || 0;
                    }
                    courseTypeList.push(par)
                })
            // this.courseTyleData.list &&
            //     this.courseTyleData.list.forEach(e => {
            //         if (!e.isTotal) {
            //             courseTypeList.push({
            //                 id: e.id,
            //                 labelId: e.labelId,
            //                 credit: e.credits,
            //                 taringingId: this.templateId,
            //                 type: 1
            //             });
            //         }
            //     });
            
            let params = {
                id: this.templateId,
                minorCultureRuleList: courseTypeList
            };
            saveCourseTypeInfo(params).then(res => {
                if (res.code == 200) {
                    this.isSaved = true;
                    this.$message({
                        message: "保存成功",
                        type: "success"
                    });
                }
            });
        },
        //撤销
        revokeTemplate(row) {
            let params = {
                idSet: row.id
            };
            this.$confirm("您确定要撤销吗？", "撤销", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(() => {
                    revokeTemplate(params).then(res => {
                        if (res.code == 200) {
                            this.$message({
                                type: "success",
                                message: "撤销成功!"
                            });
                            this.initCultureTemplateList();
                        } else {
                            this.$message({
                                type: "warning",
                                message: res.msg
                            });
                        }
                    });
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消撤销"
                    });
                });
        },
        viewTemplate(row) {
            this.viewFlag = true;
            this.optionType = 2;
            this.templateTitle = row.name;
            this.templateId = row.id;
            this.key = "addCultureTemplate";
            this.sectionData.list = [];
            queryTemplateInfo(row.id).then(res => {
                if (res.code == 200) {
                    this.editFlag = true;
                    this.defaultValue = 1;
                    this.createbasicForm = {
                        templateName: res.data.name,
                        templateNameEn: res.data.nameEn,
                        minorGrade: res.data.minorGrade && (res.data.minorGrade + '') || '',
                        advancedLevel: res.data.advancedLevelCode,
                        schoolTerm: res.data.schoolTerm
                    };

                    res.data.sonCultureTemplateList &&
                        res.data.sonCultureTemplateList.forEach(e => {
                            this.sectionData.list.push({
                                isShow: false,
                                disabledFlag: true,
                                sectionId: e.id,
                                sectionName: e.name,
                                sectionNameEn: e.nameEn,
                                contentWay: e.contentImportType + ""
                            });
                        });
                }
            });
        },
        returnList() {
            if (!this.chapterSaved) {
                // this.save();
                if (this.key === "addChapterSet") {
                    this.$refs.chapterSet.saveChapter(true);
                }
            }else {
                this.key = "cultureList";
                this.defaultValue = 0;
                this.initCultureTemplateList();
            }
        },
        //分页查询
        pageChange({ pageSize, pageNum }) {
            if (this.pageSize != pageSize) {
                this.pageSize = pageSize;
                this.pageNum = 1;
            } else {
                this.pageNum = pageNum;
            }
            this.initCultureTemplateList();
        },
        clickItem(item, index) {
            if (!this.templateId) {
                this.$message.warning("请先保存模板基础信息");
                return;
            }              
            this.topNavItems.forEach(item => {
                item.active = item.index === index;
            });
            this.defaultValue = index + 1;
            this.key = item.value;
        },
        handelSelect(val, message) {
            this.isNext = val;
            this.addCourseWrongTip = message;
            if (this.optionType == 2) {
                this.isNext = true;
                this.addCourseWrongTip = null;
            }
        },
        copy() {
            this.getSelectRows();
            if (this.templateIds.length === 0) {
                this.$message({
                    type: "info",
                    message: "请选择要复制的培养方案模板"
                });
                return;
            }
            const now = new Date();
            const currentYear = now.getFullYear()+1;
            const minYear = currentYear - 7;
            for (let year = currentYear+4; year > minYear; year--) {
                const obj = { label: year, value: year };
                this.options.grade.push(obj);
            }
            this.copyVisible = true;
        },
        copyOk(formName) {
            this.$refs[formName].validate(valid => {
                if (valid) {
                    let param = {
                        year: this.copyForm.year,
                        idSet: this.templateIds
                    }
                    copyMinorCultureTemplate(param).then(res => {
                        if (res.code === 200) {
                            this.$message({
                                type: "success",
                                message: "复制成功"
                            });
                            this.copyVisible = false;
                            this.templateIds = [];
                            this.$refs[formName].resetFields();
                            this.initCultureTemplateList();
                        }
                    })
                }
            });
        },
        resetCopy(formName) {
            this.copyVisible = false;
            this.templateIds = [];
            this.$refs[formName].resetFields();
        },
        objectSpanMethod({ row, columnIndex}) {
            if (columnIndex === 0 && !row.isTotal) {
                if (row.isFirst) {
                    return {
                        rowspan: row.len,
                        colspan: 1
                    };
                } else {
                    return {
                        rowspan: 0,
                        colspan: 0
                    };
                }
            }
        },
        addCourseCategory() {
            this.courseCategoryShow = true;
        },
        removeCourse(id) {
            this.$confirm(
                "确定要删除吗",
                    "提示",
                {
                    confirmButtonText: this.$t("common.btn.confirm"),
                    cancelButtonText: this.$t("common.btn.cancel"),
                    type: "warning"
                }
            ).then(() => {
                 deleteMinorCoursesLabeById({
                    type: 1,
                    id
                }).then(res =>{
                    if (res && res.code == 200) {
                        this.initCourseTypeData();
                        this.$message({
                            type: "success",
                            message: this.$t("common.tips.deleteSuccess")
                        });
                    }
                })
            })
           
        },
        relationCancel() {
            this.key = "addChapterSet";
            this.chapterSaved = false;
        },
        relationOk() {
            this.save();
        },
        previewTemp(row) {
            this.$router.push({
                name: 'minorCultureTempView',
                params: {
                    id: row.id,
                    title: row.name 
                }

            })
        }
    }
};
</script>
<style lang="scss" scoped>
.tip-message {
    margin: 10px 0;
    font-size: 14px;
    color: #909090;
}
.first_title {
    font-size: 18px;
    font-family: "微软雅黑";
    color: #2b3b4e;
    padding: 0px 0px 16px;
}
.btn {
    text-align: right;
    padding: 0px 0px 16px;
}
.templateFont {
    font-family: PingFangSC-Medium;
    font-size: 18px;
    color: #2b3b4e;
    letter-spacing: 0;
    line-height: 20px;
    font-weight: bold;
    float: left;
    margin-bottom: 16px;
}
.edu-page-title {
    margin-bottom: -5px;
    margin-left: 5px;
    span {
        cursor: pointer;
        display: inline-block;
        padding-right: 20px;
        color: #8896a7;
        font-weight: 400;
        border-right: 0;
        font-size: 16px;
    }
    span.active {
        padding: 8px 15px;
        color: #66b1ff;
        background: #fff;
        font-weight: 500;
        font-size: 16px;

    }
}
.stepstyle .el-step.is-horizontal .el-step__line {
    top: 15px;
}
.stepstyle .el-step__icon {
    width: 32px;
    height: 32px;
}
.stepstyle {
    width: 80%;
    margin: 0 auto 16px;
}
.returnBtn {
    float: right;
}
.parentDiv {
    padding: 0 0 24px;
}
.sectionBtn {
    margin: 25px 0;
    float: right;
}
.bottomDiv {
    float: right;
    margin: 20px 0;
}
</style>




